﻿var DataManagerModule = (function () {
    function sendOffer() {
        var carType = $('select[name=carType] option:selected').val();
        var carBrand = $('select[name=carBrand] option:selected').val();
        var carYear = $('input[name=year]').val();
        var carSeats = $('input[name=seats]').val();
        var carConsumption = $('input[name=consumption]').val();
        var vehicle = new TripDetails.Vehicle(carType, carBrand, carYear, carSeats, carConsumption);

        var fname = $('input[name="firstName"]').val();
        var lname = $('input[name="lastName"]').val();
        var email = $('input[name="email"]').val();
        var phone = $('input[name="phone"]').val();
        var age = $('input[name="age"]').val();
        var gender = $('input[name="gender"]:checked').val();
        var requirements = $('textarea[name="requirements"]').val();
        var rating = undefined;
        var driver = new TripDetails.Driver(fname, lname, email, phone, age, gender, vehicle, rating, requirements);

        var tripFrom=$('#routeFrom option:selected').val();
        var tripTo=$('#routeTo option:selected').val();
        var TripDistance=$('input[name=distance]').val();
        var tripDateOfDeparture = $('#date-time-picker-offer').val();
        var trip = new TripDetails.Trip(tripFrom, tripTo, TripDistance, tripDateOfDeparture);

        var priceValue = $('input[name=price]').val();
        var currency=$('#currency option:selected').val();
        var price = new TripDetails.Price(priceValue, currency);

        var offer = new TripDetails.Offer(driver, price, trip);
        var put = new dbModule.Put(offer);
        $("#content").load("listResults.html");
    }

    function sendSearchRequest() {
        var from = $('#searchFrom option:selected').val();
        var to = $('#searchTo option:selected').val();
        var dateTime = $("#date-time-picker-search").val();
        var distance = undefined;
        var trip = new TripDetails.Trip(from, to, distance, dateTime);
    }

    return {
        sendOffer: sendOffer,
        sendSearchRequest:sendSearchRequest
    }
})();